home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / larn.lha / store.c < prev    next >
C/C++ Source or Header  |  1995-11-19  |  29KB  |  798 lines

  1. /* store.c */
  2. /*
  3. This module contains data and routines to handle buildings at the home level.
  4. Routines:
  5.  
  6.   dnd_2hed
  7.   dnd_hed
  8.   dndstore      The DND store main routine
  9.   handsfull     To tell the player he can carry no more
  10.   out_of_stock  To tell the player an item is out of stock
  11.   no_gold       To tell the player he has no gold
  12.   dnditem       Display DND store items
  13.   sch_head      print the school header
  14.   oschool       main school routine
  15.   obank         Larn National Bank
  16.   obank2        5th level branch of the bank
  17.   banktitle     bank header
  18.   ointerest     accrue interest to bank account
  19.   obanksub      bank main subroutine
  20.   otradhead     trading post header
  21.   otradepost    trading post main function
  22.   cnsitm
  23.   olrs          larn revenue service function
  24. */
  25.  
  26. #include "header.h"
  27. #include "larndefs.h"
  28. #include "objects.h"
  29. #include "player.h"
  30.  
  31. static int dndcount=0,dnditm=0;
  32.  
  33. /* number of items in the dnd inventory table   */
  34. #define MAXITM 83
  35.  
  36. /*  this is the data for the stuff in the dnd store */
  37. struct _itm itm[90] = {
  38. /*cost    memory    iven name   iven arg   how
  39.   gp     pointer      iven[]    ivenarg[]  many */
  40.  
  41. { 2,        0,      OLEATHER,       0,      3   },
  42. { 10,       0,      OSTUDLEATHER,   0,      2   },
  43. { 40,       0,      ORING,          0,      2   },
  44. { 85,       0,      OCHAIN,         0,      2   },
  45. { 220,      0,      OSPLINT,        0,      1   },
  46. { 400,      0,      OPLATE,         0,      1   },
  47. { 900,      0,      OPLATEARMOR,    0,      1   },
  48. { 2600,     0,      OSSPLATE,       0,      1   },
  49. { 150,      0,      OSHIELD,        0,      1   },
  50.  
  51. /*cost    memory    iven name   iven arg   how
  52.   gp     pointer      iven[]    ivenarg[]  many */
  53.  
  54. { 2,        0,      ODAGGER,        0,      3   },
  55. { 20,       0,      OSPEAR,         0,      3   },
  56. { 80,       0,      OFLAIL,         0,      2   },
  57. { 150,      0,      OBATTLEAXE,     0,      2   },
  58. { 450,      0,      OLONGSWORD,     0,      2   },
  59. { 1000,     0,      O2SWORD,        0,      2   },
  60. { 5000,     0,      OSWORD,         0,      1   },
  61. { 16500,    0,      OLANCE,         0,      1   },
  62. { 6000,     0,   OSWORDofSLASHING,  0,      0   },
  63. { 10000,    0,      OHAMMER,        0,      0   },
  64.  
  65. /*cost    memory    iven name   iven arg   how
  66.   gp     pointer      iven[]    ivenarg[]  many */
  67.  
  68. { 150,      0,      OPROTRING,      1,      1   },
  69. { 85,       0,      OSTRRING,       1,      1   },
  70. { 120,      0,      ODEXRING,       1,      1   },
  71. { 120,      0,      OCLEVERRING,    1,      1   },
  72. { 180,      0,      OENERGYRING,    0,      1   },
  73. { 125,      0,      ODAMRING,       0,      1   },
  74. { 220,      0,      OREGENRING,     0,      1   },
  75. { 1000,     0,      ORINGOFEXTRA,   0,      1   },
  76.  
  77. { 280,      0,      OBELT,          0,      1   },
  78.  
  79. { 400,      0,      OAMULET,        0,      1   },
  80.  
  81. { 6500,     0,      OORBOFDRAGON,   0,      0   },
  82. { 5500,     0,      OSPIRITSCARAB,  0,      0   },
  83. { 5000,     0,      OCUBEofUNDEAD,  0,      0   },
  84. { 6000,     0,      ONOTHEFT,       0,      0   },
  85.  
  86. { 590,      0,      OCHEST,         6,      1   },
  87. { 200,      0,      OBOOK,          8,      1   },
  88. { 10,       0,      OCOOKIE,        0,      3   },
  89.  
  90. /*cost    memory    iven name   iven arg   how
  91.   gp     pointer      iven[]    ivenarg[]  many */
  92.  
  93. {   20,     potionname, OPOTION,    0,      6   },
  94. {   90,     potionname, OPOTION,    1,      5   },
  95. {   520,    potionname, OPOTION,    2,      1   },
  96. {   100,    potionname, OPOTION,    3,      2   },
  97. {   50,     potionname, OPOTION,    4,      2   },
  98. {   150,    potionname, OPOTION,    5,      2   },
  99. {   70,     potionname, OPOTION,    6,      1   },
  100. {   30,     potionname, OPOTION,    7,      7   },
  101. {   200,    potionname, OPOTION,    8,      1   },
  102. {   50,     potionname, OPOTION,    9,      1   },
  103. {   80,     potionname, OPOTION,    10,     1   },
  104.  
  105. /*cost    memory    iven name   iven arg   how
  106.   gp     pointer      iven[]    ivenarg[]  many */
  107.  
  108. {   30,     potionname, OPOTION,    11,     3   },
  109. {   20,     potionname, OPOTION,    12,     5   },
  110. {   40,     potionname, OPOTION,    13,     3   },
  111. {   35,     potionname, OPOTION,    14,     2   },
  112. {   520,    potionname, OPOTION,    15,     1   },
  113. {   90,     potionname, OPOTION,    16,     2   },
  114. {   200,    potionname, OPOTION,    17,     2   },
  115. {   220,    potionname, OPOTION,    18,     4   },
  116. {   80,     potionname, OPOTION,    19,     6   },
  117. {   370,    potionname, OPOTION,    20,     3   },
  118. {   50,     potionname, OPOTION,    22,     1   },
  119. {   150,    potionname, OPOTION,    23,     3   },
  120.  
  121. /*cost    memory    iven name   iven arg   how
  122.   gp     pointer      iven[]    ivenarg[]  many */
  123.  
  124. { 100,  scrollname,     OSCROLL,    0,      2   },
  125. { 125,  scrollname,     OSCROLL,    1,      2   },
  126. { 60,   scrollname,     OSCROLL,    2,      4   },
  127. { 10,   scrollname,     OSCROLL,    3,      4   },
  128. { 100,  scrollname,     OSCROLL,    4,      3   },
  129. { 200,  scrollname,     OSCROLL,    5,      2   },
  130. { 110,  scrollname,     OSCROLL,    6,      1   },
  131. { 500,  scrollname,     OSCROLL,    7,      2   },
  132. { 200,  scrollname,     OSCROLL,    8,      2   },
  133. { 250,  scrollname,     OSCROLL,    9,      4   },
  134. { 20,   scrollname,     OSCROLL,    10,     5   },
  135. { 30,   scrollname,     OSCROLL,    11,     3   },
  136.  
  137. /*cost    memory    iven name   iven arg   how
  138.   gp     pointer      iven[]    ivenarg[]  many */
  139.  
  140. { 340,  scrollname,     OSCROLL,    12,     1   },
  141. { 340,  scrollname,     OSCROLL,    13,     1   },
  142. { 300,  scrollname,     OSCROLL,    14,     2   },
  143. { 400,  scrollname,     OSCROLL,    15,     2   },
  144. { 500,  scrollname,     OSCROLL,    16,     2   },
  145. { 1000, scrollname,     OSCROLL,    17,     1   },
  146. { 500,  scrollname,     OSCROLL,    18,     1   },
  147. { 340,  scrollname,     OSCROLL,    19,     2   },
  148. { 220,  scrollname,     OSCROLL,    20,     3   },
  149. { 3900, scrollname,     OSCROLL,    21,     0   },
  150. { 610,  scrollname,     OSCROLL,    22,     1   },
  151. { 3000, scrollname,     OSCROLL,    23,     0   }
  152.  };
  153.  
  154. /*
  155.     for the college of larn
  156.  */
  157. char course[26];    /*  the list of courses taken   */
  158. static char coursetime[] = { 10, 15, 10, 20, 10, 10, 10, 5 };
  159.  
  160. /*
  161.     function for the dnd store
  162.  */
  163. static dnd_2hed()
  164.     {
  165.     lprcat("Welcome to the Larn Thrift Shoppe.  We stock many items explorers find useful\n");
  166.     lprcat(" in their adventures.  Feel free to browse to your hearts content.\n");
  167.     lprcat("Also be advised, if you break 'em, you pay for 'em.");
  168.     }
  169.  
  170. static dnd_hed()
  171.     {
  172.     register int i;
  173.     for (i=dnditm; i<26+dnditm; i++)    dnditem(i);
  174.     cursor(50,18); lprcat("You have ");
  175.     }
  176.  
  177. dndstore()
  178.   {
  179.   register int i;
  180.   dnditm = 0;
  181.   nosignal = 1; /* disable signals */
  182.   clear();  dnd_2hed();
  183.   if (outstanding_taxes>0)
  184.     {
  185.     lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n"); beep();
  186.     lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n",(long)outstanding_taxes);
  187.     lprcat("comply with the law, we cannot serve you at this time.  Soo Sorry.\n");
  188.     cursors();
  189.     lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush();
  190.     i=0;
  191.     while (i!='\33') i=ttgetch();
  192.     drawscreen();  nosignal = 0; /* enable signals */ return;
  193.     }
  194.  
  195.   dnd_hed();
  196.   while (1)
  197.     {
  198.     cursor(59,18); lprintf("%d gold pieces",(long)c[GOLD]);
  199.     cltoeoln(); cl_dn(1,20);    /* erase to eod */
  200.     lprcat("\nEnter your transaction ["); standout("space");
  201.     lprcat(" for more, "); standout("escape");
  202.     lprcat(" to leave]? ");
  203.     i=0;
  204.     while ((i<'a' || i>'z') && (i!=' ') && (i!='\33') && (i!=12))  i=ttgetch();
  205.     if (i==12) { clear();  dnd_2hed();  dnd_hed(); }
  206.     else if (i=='\33')
  207.         { drawscreen();  nosignal = 0; /* enable signals */ return; }
  208.     else if (i==' ')
  209.         {
  210.         cl_dn(1,4);
  211.     if ((dnditm += 26) >= MAXITM)
  212.             dnditm=0;
  213.         dnd_hed();
  214.         }
  215.     else
  216.         {  /* buy something */
  217.         lprc(i);    /* echo the byte */
  218.         i += dnditm - 'a';
  219.     if (i>=MAXITM) outofstock(); else
  220.         if (itm[i].qty <= 0) outofstock(); else
  221.         if (pocketfull()) handsfull(); else
  222.         if (c[GOLD] < (long) itm[i].price * 10) nogold(); else
  223.             {
  224.             if (itm[i].mem != 0) *itm[i].mem[itm[i].arg] = ' ';
  225.             c[GOLD] -= (long) itm[i].price * 10;
  226.             itm[i].qty--;  take(itm[i].obj,itm[i].arg);
  227.             if (itm[i].qty==0) dnditem(i);  nap(1001);
  228.             }
  229.         }
  230.  
  231.     }
  232.   }
  233.  
  234. /*
  235.     function for the players hands are full
  236.  */
  237. static handsfull()
  238.     { lprcat("\nYou can't carry anything more!"); lflush(); nap(2200); }
  239. static outofstock()
  240.     { lprcat("\nSorry, but we are out of that item."); lflush(); nap(2200); }
  241. static nogold()
  242.     { lprcat("\nYou don't have enough gold to pay for that!"); lflush(); nap(2200); }
  243.  
  244. /*
  245.     dnditem(index)
  246.  
  247.     to print the item list;  used in dndstore() enter with the index into itm
  248.  */
  249. static dnditem(i)
  250.     register int i;
  251.     {
  252.     register int j,k;
  253.     if (i >= MAXITM)  return;
  254.     cursor( (j=(i&1)*40+1) , (k=((i%26)>>1)+5) );
  255.     if (itm[i].qty == 0)  { lprintf("%39s","");  return; }
  256.     lprintf("%c) ",(i%26)+'a');
  257.     if (itm[i].obj == OPOTION)
  258.         { lprcat("potion of "); lprintf("%s",&potionname[itm[i].arg][1]); }
  259.     else if (itm[i].obj == OSCROLL)
  260.         { lprcat("scroll of "); lprintf("%s",&scrollname[itm[i].arg][1]); }
  261.     else lprintf("%s",objectname[itm[i].obj]);
  262.     cursor( j+31,k );  lprintf("%6d", (long) itm[i].price * 10);
  263.     }
  264.  
  265.  
  266. /*
  267.     function to display the header info for the school
  268.  */
  269. static sch_hed()
  270.     {
  271.     clear();
  272.     lprcat("The College of Larn offers the exciting opportunity of higher education to\n");
  273.     lprcat("all inhabitants of the caves.  Here is a list of the class schedule:\n\n\n");
  274.     lprcat("\t\t    Course Name \t       Time Needed\n\n");
  275.  
  276.     if (course[0]==0) lprcat("\t\ta)  Fighters Training I         10 mobuls"); /*line 7 of crt*/
  277.     lprc('\n');
  278.     if (course[1]==0) lprcat("\t\tb)  Fighters Training II        15 mobuls");
  279.     lprc('\n');
  280.     if (course[2]==0) lprcat("\t\tc)  Introduction to Wizardry    10 mobuls");
  281.     lprc('\n');
  282.     if (course[3]==0) lprcat("\t\td)  Applied Wizardry            20 mobuls");
  283.     lprc('\n');
  284.     if (course[4]==0) lprcat("\t\te)  Behavioral Psychology       10 mobuls");
  285.     lprc('\n');
  286.     if (course[5]==0) lprcat("\t\tf)  Faith for Today             10 mobuls");
  287.     lprc('\n');
  288.     if (course[6]==0) lprcat("\t\tg)  Contemporary Dance          10 mobuls");
  289.     lprc('\n');
  290.     if (course[7]==0) lprcat("\t\th)  History of Larn              5 mobuls");
  291.  
  292.     lprcat("\n\n\t\tAll courses cost 250 gold pieces.");
  293.     cursor(30,18);
  294.     lprcat("You are presently carrying ");
  295.     }
  296.  
  297. oschool()
  298.     {
  299.     register int i;
  300.     long time_used;
  301.     nosignal = 1; /* disable signals */
  302.     sch_hed();
  303.     while (1)
  304.         {
  305.         cursor(57,18); lprintf("%d gold pieces.   ",(long)c[GOLD]); cursors();
  306.         lprcat("\nWhat is your choice ["); standout("escape");
  307.         lprcat(" to leave] ? ");  yrepcount=0;
  308.         i=0;  while ((i<'a' || i>'h') && (i!='\33') && (i!=12)) i=ttgetch();
  309.         if (i==12) { sch_hed();  continue; }
  310.         else if (i=='\33')
  311.             { nosignal = 0; drawscreen();  /* enable signals */ return; }
  312.         lprc(i);
  313.         if (c[GOLD] < 250)  nogold();  else
  314.         if (course[i-'a'])
  315.             { lprcat("\nSorry, but that class is filled."); nap(1000); }
  316.         else
  317.         if (i <= 'h')
  318.             {
  319.             c[GOLD] -= 250; time_used=0;
  320.             switch(i)
  321.                 {
  322.                 case 'a':   c[STRENGTH] += 2;  c[CONSTITUTION]++;
  323.                             lprcat("\nYou feel stronger!");
  324.                             cl_line(16,7);
  325.                             break;
  326.  
  327.                 case 'b':   if (course[0]==0)
  328.                                 {
  329.                                 lprcat("\nSorry, but this class has a prerequisite of Fighters Training I");
  330.                                 c[GOLD]+=250;  time_used= -10000;  break;
  331.                                 }
  332.                             lprcat("\nYou feel much stronger!");
  333.                             cl_line(16,8);
  334.                             c[STRENGTH] += 2;  c[CONSTITUTION] += 2;  break;
  335.  
  336.                 case 'c':   c[INTELLIGENCE] += 2; 
  337.                             lprcat("\nThe task before you now seems more attainable!");
  338.                             cl_line(16,9);  break;
  339.  
  340.                 case 'd':   if (course[2]==0)
  341.                                 {
  342.                                 lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry");
  343.                                 c[GOLD]+=250;  time_used= -10000;  break;
  344.                                 }
  345.                             lprcat("\nThe task before you now seems very attainable!");
  346.                             cl_line(16,10);
  347.                             c[INTELLIGENCE] += 2;  break;
  348.  
  349.                 case 'e':   c[CHARISMA] += 3;  
  350.                             lprcat("\nYou now feel like a born leader!");
  351.                             cl_line(16,11);  break;
  352.  
  353.                 case 'f':   c[WISDOM] += 2;  
  354.                             lprcat("\nYou now feel more confident that you can find the potion in time!");
  355.                             cl_line(16,12);  break;
  356.  
  357.                 case 'g':   c[DEXTERITY] += 3;  
  358.                             lprcat("\nYou feel like dancing!");
  359.                             cl_line(16,13);  break;
  360.  
  361.                 case 'h':   c[INTELLIGENCE]++;
  362.                             lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n");
  363.                             lprcat("by a platinum dragon who possesses psionic abilities. ");
  364.                             cl_line(16,14);  break;
  365.                 }
  366.             time_used += coursetime[i-'a']*100;
  367.             if (time_used > 0)
  368.               {
  369.               gtime += time_used;
  370.               course[i-'a']++;  /*  remember that he has taken that course  */
  371.               c[HP] = c[HPMAX];  c[SPELLS] = c[SPELLMAX]; /* he regenerated */
  372.  
  373.               if (c[BLINDCOUNT])    c[BLINDCOUNT]=1;  /* cure blindness too!  */
  374.               if (c[CONFUSE])       c[CONFUSE]=1;   /*  end confusion   */
  375.               adjtime((long)time_used); /* adjust parameters for time change */
  376.               }
  377.             nap(1000);
  378.             }
  379.         }
  380.     }
  381.  
  382. /*
  383.  *  for the first national bank of Larn
  384.  */
  385. int lasttime=0; /* last time he was in bank */
  386. obank()
  387.     {
  388.     banktitle("    Welcome to the First National Bank of Larn.");
  389.     }
  390. obank2()
  391.     {
  392.     banktitle("Welcome to the 5th level branch office of the First National Bank of Larn.");
  393.     /* because we state the level in the title, clear the '?' in the
  394.        level display at the bottom, if the user teleported.
  395.     */
  396.     c[TELEFLAG] = 0;
  397.     }
  398. static banktitle(str)
  399.     char *str;
  400.     {
  401.     nosignal = 1; /* disable signals */
  402.     clear();  lprcat(str);
  403.     if (outstanding_taxes>0)
  404.         {
  405.         register int i;
  406.         lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n"); beep();
  407.         lprintf("levied taxes have been paid.  They have also told us that you owe %d gp in\n",(long)outstanding_taxes);
  408.         lprcat("taxes, and we must comply with them. We cannot serve you at this time.  Sorry.\n");
  409.         lprcat("We suggest you go to the LRS office and pay your taxes.\n");
  410.         cursors();
  411.         lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush();
  412.         i=0;
  413.         while (i!='\33') i=ttgetch();
  414.         drawscreen();  nosignal = 0; /* enable signals */ return;
  415.         }
  416.     lprcat("\n\n\tGemstone\t      Appraisal\t\tGemstone\t      Appraisal");
  417.     obanksub();     nosignal = 0; /* enable signals */
  418.     drawscreen();
  419.     }
  420.  
  421. /*
  422.  *  function to put interest on your bank account
  423.  */
  424. ointerest()
  425.     {
  426.     register int i;
  427.     if (c[BANKACCOUNT]<0) c[BANKACCOUNT] = 0;
  428.     else if ((c[BANKACCOUNT]>0) && (c[BANKACCOUNT]<500000))
  429.         {
  430.         i = (gtime-lasttime)/100; /* # mobuls elapsed */
  431.         while ((i-- > 0) && (c[BANKACCOUNT]<500000))
  432.             c[BANKACCOUNT] += c[BANKACCOUNT]/250;
  433.         if (c[BANKACCOUNT]>500000) c[BANKACCOUNT]=500000; /* interest limit */
  434.         }
  435.     lasttime = (gtime/100)*100;
  436.     }
  437.  
  438. static obanksub()
  439.     {
  440.     short gemorder[26];  /* the reference to screen location for each gem */
  441.     long gemvalue[26];   /* the appraisal of the gems */
  442.     unsigned long amt;
  443.     register int i,k,gems_sold=0;
  444.  
  445.     ointerest();    /* credit any needed interest */
  446.  
  447.     for (k=i=0; i<26; i++)
  448.         switch(iven[i])
  449.             {
  450.             case OLARNEYE: case ODIAMOND: case OEMERALD:
  451.             case ORUBY: case OSAPPHIRE:
  452.  
  453.                     if (iven[i]==OLARNEYE)
  454.                         {
  455.                         gemvalue[i]=250000-((gtime*7)/100)*100;
  456.                         if (gemvalue[i]<50000) gemvalue[i]=50000;
  457.                         }
  458.                     else gemvalue[i] = (255&ivenarg[i])*100;
  459.                     gemorder[i]=k;
  460.                     cursor( (k%2)*40+1 , (k>>1)+4 );
  461.                     lprintf("%c) %s",i+'a',objectname[iven[i]]);
  462.                     cursor( (k%2)*40+33 , (k>>1)+4 );
  463.                     lprintf("%5d",(long)gemvalue[i]);  k++;
  464.                     break;
  465.  
  466.             default:        /* make sure player can't sell non-existant gems */
  467.                 gemvalue[i] = 0 ;
  468.                 gemorder[i] = 0 ;
  469.             };
  470.     cursor(31,17); lprintf("You have %8d gold pieces in the bank.",(long)c[BANKACCOUNT]);
  471.     cursor(40,18); lprintf("You have %8d gold pieces",(long)c[GOLD]);
  472.     if (c[BANKACCOUNT]+c[GOLD] >= 500000)
  473.         lprcat("\nNote:  Larndom law states that only deposits under 500,000gp  can earn interest.");
  474.     while (1)
  475.         {
  476.         cl_dn(1,20);
  477.         lprcat("\nYour wish? [("); standout("d"); lprcat(") deposit, (");
  478.         standout("w"); lprcat(") withdraw, ("); standout("s");
  479.         lprcat(") sell a stone, or "); standout("escape"); lprcat("]  ");
  480.         yrepcount=0;
  481.         i=0; while (i!='d' && i!='w' && i!='s' && i!='\33') i=ttgetch();
  482.         switch(i)
  483.             {
  484. # ifdef MSDOS
  485.             case 'd':
  486.               lprcat("deposit\n");
  487.               cltoeoln();
  488.               lprcat("How much? "); amt = readnum((long)c[GOLD]);
  489. # else
  490.             case 'd':   lprcat("deposit\nHow much? ");  amt = readnum((long)c[GOLD]);
  491. # endif
  492.                         if (amt<0) { lprcat("\nSorry, but we can't take negative gold!"); nap(2000); amt=0; } else
  493.                         if (amt>c[GOLD])
  494.                           { lprcat("  You don't have that much.");  nap(2000); }
  495.                         else { c[GOLD] -= amt;  c[BANKACCOUNT] += amt; }
  496.                         break;
  497.  
  498.             case 'w':   lprcat("withdraw\nHow much? "); amt = readnum((long)c[BANKACCOUNT]);
  499.                         if (amt<0) { lprcat("\nSorry, but we don't have any negative gold!");  nap(2000); amt=0; }
  500.                         else if (amt > c[BANKACCOUNT])
  501.                           { lprcat("\nYou don't have that much in the bank!"); nap(2000); }
  502.                         else { c[GOLD] += amt;  c[BANKACCOUNT] -= amt; }
  503.                         break;
  504.  
  505.             case 's':   lprcat("\nWhich stone would you like to sell? ");
  506.             i=0; while ((i<'a' || i>'z') && i!='*' && i!='\33')
  507.                 i=ttgetch();
  508.                         if (i=='*')
  509.               {
  510.               for (i=0; i<26; i++)
  511.                             {
  512.                             if (gemvalue[i])
  513.                                 {
  514.                 gems_sold = TRUE ;
  515.                 c[GOLD]+=gemvalue[i];  iven[i]=0;
  516.                                 gemvalue[i]=0;  k = gemorder[i];
  517.                                 cursor( (k%2)*40+1 , (k>>1)+4 );
  518.                                 lprintf("%39s","");
  519.                                 }
  520.                             }
  521.               if (!gems_sold)
  522.                   {
  523.                   lprcat("\nYou have no gems to sell!");
  524.                   nap(2000);
  525.                   }
  526.               }
  527.             else if ( i != '\33' )
  528.                             {
  529.                             if (gemvalue[i=i-'a']==0)
  530.                                 {
  531.                                 lprintf("\nItem %c is not a gemstone!",i+'a');
  532.                                 nap(2000); break;
  533.                                 }
  534.                             c[GOLD]+=gemvalue[i];  iven[i]=0;
  535.                             gemvalue[i]=0;  k = gemorder[i];
  536.                             cursor( (k%2)*40+1 , (k>>1)+4 ); lprintf("%39s","");
  537.                             }
  538.                         break;
  539.  
  540.             case '\33': return;
  541.             };
  542.         cursor(40,17); lprintf("%8d",(long)c[BANKACCOUNT]);
  543.         cursor(49,18); lprintf("%8d",(long)c[GOLD]);
  544.         }
  545.     }
  546.  
  547. /*
  548.     function for the trading post
  549.  */
  550. static otradhead()
  551.     {
  552.     clear();
  553.     lprcat("Welcome to the Larn Trading Post.  We buy items that explorers no longer find\n");
  554.     lprcat("useful.  Since the condition of the items you bring in is not certain,\n");
  555.     lprcat("and we incur great expense in reconditioning the items, we usually pay\n");
  556.     lprcat("only 20% of their value were they to be new.  If the items are badly\n");
  557.     lprcat("damaged, we will pay only 10% of their new value.\n\n");
  558.  
  559.     lprcat("Here are the items we would be willing to buy from you:\n");
  560.     }
  561.  
  562. static short tradorder[26];   /* screen locations for trading post inventory */
  563. static otradiven()
  564.     {
  565.     int i,j ;
  566.  
  567.   /* Print user's iventory like bank */
  568.   for (j=i=0 ; i<26 ; i++)
  569.       if (iven[i])
  570.           {
  571.       cursor( (j%2)*40+1, (j>>1)+8 );
  572.       tradorder[i] = 0 ;    /* init position on screen to zero */
  573.       switch (iven[i])
  574.               {
  575.               case OPOTION:
  576.           if ( potionname[ivenarg[i]][0] != 0 )
  577.               {
  578.               tradorder[i] = j++ ;   /* will display only if identified */
  579.               lprintf( "%c) %s", i+'a', objectname[iven[i]] );
  580.               lprintf(" of%s", potionname[ivenarg[i]] );
  581.               }
  582.                   break;
  583.               case OSCROLL:
  584.           if ( scrollname[ivenarg[i]][0] != 0 )
  585.               {
  586.               tradorder[i] = j++ ;   /* will display only if identified */
  587.               lprintf( "%c) %s", i+'a', objectname[iven[i]] );
  588.               lprintf(" of%s", scrollname[ivenarg[i]] );
  589.               }
  590.           break;
  591.           case OLARNEYE:
  592.           case OBOOK:
  593.           case OSPIRITSCARAB:
  594.           case ODIAMOND:
  595.           case ORUBY:
  596.           case OEMERALD:
  597.           case OCHEST:
  598.           case OSAPPHIRE:
  599.           case OCUBEofUNDEAD:
  600.           case OCOOKIE:
  601.           case ONOTHEFT:
  602.           tradorder[i] = j++ ;  /* put on screen */
  603.           lprintf( "%c) %s", i+'a', objectname[iven[i]] );
  604.           break;
  605.           default:
  606.           tradorder[i] = j++ ;  /* put on screen */
  607.           lprintf( "%c) %s", i+'a', objectname[iven[i]] );
  608.           if (ivenarg[i] > 0)
  609.               lprintf(" +%d", (long)ivenarg[i] );
  610.           else if (ivenarg[i] < 0)
  611.               lprintf(" %d",  (long)ivenarg[i] );
  612.           break;
  613.           }
  614.       }
  615.       else
  616.        tradorder[i] = 0;  /* make sure order array is clear */
  617.     }
  618.  
  619. static cleartradiven( i )
  620. int i ;
  621.     {
  622.     int j;
  623.     j = tradorder[i] ;
  624.     cursor( (j%2)*40+1, (j>>1)+8 );
  625.     lprintf( "%39s", "" );
  626.     tradorder[i] = 0;
  627.     }
  628.  
  629. otradepost()
  630.     {
  631.     register int i,j,isub,izarg,found;
  632.     register long value;
  633.  
  634.     dnditm = dndcount = 0;
  635.     nosignal = 1; /* disable signals */
  636.     otradhead();
  637.     otradiven();
  638.  
  639.     while (1)
  640.        {
  641.        cl_dn(1,21);
  642.        lprcat("\nWhat item do you want to sell to us [");
  643.        standout("escape"); lprcat("] ? ");
  644.        i=0;
  645.        while ( i>'z' || i<'a' && i!=12 && i!='\33' )
  646.            i=ttgetch();
  647.        if (i == '\33')
  648.            {
  649.            recalc();
  650.            drawscreen();
  651.            nosignal=0; /* enable signals */
  652.            return;
  653.            }
  654.        while (1)   /* inner loop for simpler control */
  655.            {
  656.            if (i == 12)
  657.                {
  658.                clear();
  659.                otradhead();
  660.                otradiven();
  661.                break;      /* leave inner while */
  662.                }
  663.  
  664.            isub = i - 'a' ;
  665.            if (iven[isub] == 0)
  666.                {
  667.                lprintf("\nYou don't have item %c!",isub+'a');
  668.                nap(2000);
  669.                break;      /* leave inner while */
  670.                }
  671.            if (iven[isub]==OSCROLL)
  672.                if (scrollname[ivenarg[isub]][0]==0)
  673.                    {
  674.                    cnsitm();
  675.                    break;      /* leave inner while */
  676.                    }
  677.            if (iven[isub]==OPOTION)
  678.                if (potionname[ivenarg[isub]][0]==0)
  679.                    {
  680.                    cnsitm();
  681.                    break;      /* leave inner while */
  682.                    }
  683.            if (iven[isub]==ODIAMOND ||
  684.                iven[isub]==ORUBY    ||
  685.                iven[isub]==OEMERALD ||
  686.            iven[isub]==OSAPPHIRE )
  687.            value = 20L * (ivenarg[isub] & 255);
  688.        else if (iven[isub]==OLARNEYE)
  689.            {
  690.            value = 50000 - (((gtime*7) / 100) * 20 );
  691.            if (value < 10000)
  692.            value = 10000;
  693.            }
  694.        else
  695.                {
  696.                /* find object in itm[] list for price info */
  697.                found = MAXITM ;
  698.                for (j=0; j<MAXITM; j++)
  699.                    if (itm[j].obj == iven[isub])
  700.                        {
  701.                        found = j ;
  702.                        break;      /* leave for loop */
  703.                        }
  704.                if (found == MAXITM)
  705.                    {
  706.                    lprcat("\nSo sorry, but we are not authorized to accept that item.");
  707.                    nap(2000);
  708.                    break;      /* leave inner while */
  709.                    }
  710.                if (iven[isub] == OSCROLL ||
  711.                    iven[isub] == OPOTION)
  712.                    value = 2 * (long)itm[ j + ivenarg[isub]].price ;
  713.                else
  714.                    {
  715.                    izarg=ivenarg[isub];
  716.                    value = itm[j].price;
  717.                    /* appreciate if a +n object */
  718.                    if (izarg >= 0) value *= 2;
  719.                    while ((izarg-- > 0) && ((value=14*(67+value)/10) < 500000));
  720.                    }
  721.                }
  722.            /* we have now found the value of the item, and dealt with any error
  723.               cases.  Print the object's value, let the user sell it.
  724.            */
  725.            lprintf("\nItem (%c) is worth %d gold pieces to us.  Do you want to sell it? ",i,(long)value);
  726.            yrepcount=0;
  727.            if (getyn()=='y')
  728.                {
  729.                lprcat("yes\n"); c[GOLD]+=value;
  730.                if (c[WEAR] == isub) c[WEAR] = -1;
  731.                if (c[WIELD] == isub) c[WIELD] = -1;
  732.                if (c[SHIELD] == isub) c[SHIELD] = -1;
  733.                adjustcvalues(iven[isub],ivenarg[isub]);
  734.                iven[isub]=0;
  735.                cleartradiven( isub );
  736.                }
  737.            else
  738.            {
  739.            lprcat("no thanks.\n");
  740.            nap(500);
  741.            }
  742.        break;          /* exit inner while */
  743.            }   /* end of inner while */
  744.         }       /* end of outer while */
  745.     }       /* end of routine */
  746.  
  747. static cnsitm()
  748.     {
  749.     lprcat("\nSorry, we can't accept unidentified objects.");
  750.     nap(2000);
  751.     }
  752.  
  753. /*
  754.  *  for the Larn Revenue Service
  755.  */
  756. olrs()
  757.     {
  758.     register int i,first;
  759.     unsigned long amt;
  760.     first = nosignal = 1; /* disable signals */
  761.     clear();  resetscroll(); cursor(1,4);
  762.     lprcat("Welcome to the Larn Revenue Service district office.  How can we help you?");
  763.     while (1)
  764.         {
  765.         if (first) { first=0; goto nxt; }
  766.         setscroll();
  767.         cursors();
  768.         lprcat("\n\nYour wish? [(");
  769.         standout("p");
  770.         lprcat(") pay taxes, or ");
  771.         standout("escape");
  772.         lprcat("]  ");  yrepcount=0;
  773.         i=0; while (i!='p' && i!='\33') i=ttgetch();
  774.         switch(i)
  775.             {
  776.             case 'p':   lprcat("pay taxes\nHow much? "); amt = readnum((long)c[GOLD]);
  777.                         if (amt<0) { lprcat("\nSorry, but we can't take negative gold\n"); amt=0; } else
  778.                         if (amt>c[GOLD])    lprcat("  You don't have that much.\n");
  779.                         else  c[GOLD] -= paytaxes((long)amt);
  780.                         break;
  781.  
  782.             case '\33': nosignal = 0; /* enable signals */
  783.                         setscroll(); drawscreen();  return;
  784.             };
  785.  
  786. nxt:    cursor(1,6);
  787.         if (outstanding_taxes>0)
  788.             lprintf("You presently owe %d gp in taxes.  ",(long)outstanding_taxes);
  789.         else
  790.             lprcat("You do not owe us any taxes.           ");
  791.         cursor(1,8);
  792.         if (c[GOLD]>0)
  793.             lprintf("You have %6d gp.    ",(long)c[GOLD]);
  794.         else
  795.             lprcat("You have no gold pieces.  ");
  796.         }
  797.     }
  798.